package org.idea.qiyu.framework.shutdown.config;

import org.idea.qiyu.framework.shutdown.listener.GracefulShutdownListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author linhao
 * @Date created in 10:33 下午 2021/7/15
 */
@Configuration
public class GracefulShutdownAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public GracefulShutdownListener gracefulShutdownListener(){
        return new GracefulShutdownListener();
    }

    @Bean
    public ServletWebServerFactory tomcatServletWebServerFactory(GracefulShutdownListener gracefulShutdownListener){
        TomcatServletWebServerFactory tomcatServletWebServerFactory = new TomcatServletWebServerFactory();
        tomcatServletWebServerFactory.addConnectorCustomizers(gracefulShutdownListener);
        return tomcatServletWebServerFactory;
    }
}
